<template>
    <div class="category">
        <van-sidebar v-model="activeKey" @change="onChange">
            <van-sidebar-item v-for="item in category" :key="item.categoryName" :title="item.categoryName" />
        </van-sidebar>
        <div class="contents" ref="content">
            <div class="content" v-for="(item, index) in category" :key="item.categoryName">
                <template v-if="activeKey == index">
                    <div class="item" v-for="good in item.childrenNodeList" :key="good.categoryName">
                        <p class="list_title">
                            {{ good.categoryName }}
                        </p>
                        <div class="subitems">
                            <div class="subitem" v-for="item1 in good.childrenNodeList" :key="item1.categoryName">
                                <img :src="item1.appIcon" alt="">
                                <p>{{ item1.categoryName }}</p>
                            </div>
                        </div>
                    </div>
                </template>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    created() {
        this.$api.getCategory().then(res => {
            this.category = res.body.data.topLevelFrontCategoryVOList;
        })
    },
    data() {
        return {
            activeKey: 0,
            category: []
        };
    },
    methods: {
        onChange() {
            this.$refs.content.scrollTop = 0;
        },
    },
};
</script>

<style lang="less">
.category {
    margin-bottom: 50px;
    height: calc(100vh);
    display: flex;

    .van-sidebar {
        height: 100%;
        width: 100px;
        background: #fff;
        box-shadow: inset -1px 0 0 0 #ddd;
        display: flex;
        flex-direction: column;
        flex-shrink: 0;
        align-items: center;

        .van-sidebar-item {
            background-color: transparent;
            position: relative;
            overflow: hidden;
            flex: 0 0 50px;
            display: flex;
            width: 100%;
            justify-content: center;
            align-items: center;

            .van-sidebar-item__text {
                flex: 0 0 auto;
                font-size: 14px;
                color: #666;
                max-width: 84px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                font-family: PingFangSC-Regular;
                letter-spacing: 0;
            }
        }

        .van-sidebar-item--select::before {
            display: none;
        }

        .van-sidebar-item--select {

            .van-sidebar-item__text {
                background-image: linear-gradient(-90deg, red, #ff3264);
                border-radius: 25px;
                font-family: PingFangSC-Regular;
                font-size: 14px;
                color: #fff;
                letter-spacing: 0;
                padding: 2.5px 7px;
            }
        }
    }

    .contents {
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow-y: auto;
        padding: 10px 10px 0px;

        .content {

            .item {
                padding-bottom: 7px;
                border-bottom: 0.5px solid #f0f0f0;

                .list_title {
                    font-size: 14px;
                    line-height: 30px;
                    height: 30px;
                    margin-bottom: 8px;
                    font-family: PingFangSC-Semibold;
                    color: #333;
                    letter-spacing: 0;
                    font-weight: 700;
                }

                .subitems {
                    display: flex;
                    flex-wrap: wrap;

                    .subitem {
                        flex: 0 0 33.33%;
                        padding: 0 4px;

                        img {
                            width: 100%;
                        }

                        p {
                            font-family: PingFangSC-Light;
                            text-align: center;
                            font-size: 12px;
                            color: #1e1e1e;
                            display: -webkit-box;
                            -webkit-box-orient: vertical;
                            -webkit-line-clamp: 2;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: normal;
                            margin-bottom: 14px;
                        }
                    }
                }
            }
        }
    }

}
</style>